package Unicart.pages;

import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class RegistrationPage extends AnyPage {

  public RegistrationPage(PageManager pages) {
		super(pages);
  }
	
  @FindBy(id = "registration_name")
  private WebElement usernameRegField;
  
  @FindBy(id = "registration_surname")
  private WebElement usersurnameRegField;
	
  @FindBy(id = "registration_email")
  private WebElement emailRegField;
  
  @FindBy(id = "registration_login")
  private WebElement loginRegField;
  
  @FindBy(id = "registration_password_password")
  private WebElement passwordRegField;
  
  @FindBy(id = "registration_password_password_repeat")
  private WebElement password2RegField;
  
  @FindBy(id = "registration_agreement")
  private WebElement regAgreementCheckbox;
  
  @FindBy(name = "submit")
  private WebElement submitButton;
  
  public RegistrationPage setUsernameRegField(String text) {
    usernameRegField.sendKeys(text);
    return this;
  }
  
  public RegistrationPage setUsersurnameRegField(String text) {
	usersurnameRegField.sendKeys(text);
	return this;
  }

  public RegistrationPage setEmailRegField(String text) {
    emailRegField.sendKeys(text);
    return this;
  }
  
  public RegistrationPage setLoginRegField(String text) {
	loginRegField.sendKeys(text);
	return this;
  }

  public RegistrationPage setRegPassword(String text) {
    passwordRegField.sendKeys(text);
    return this;
  }

  public RegistrationPage setRegPassword2(String text) {
    password2RegField.sendKeys(text);
    return this;
  }

  //checkbox?
  public RegistrationPage clickRegAgreementCheckbox() {
	regAgreementCheckbox.click();
	return this;
  }
  
  public RegistrationPage ensurePageLoaded() {
    super.ensurePageLoaded();
    wait.until(presenceOfElementLocated(By.cssSelector("input#registration_name")));
    wait.until(presenceOfElementLocated(By.cssSelector("div.b-page-content_in h1")));
    return this;
  }
  
  public InternalPage clickSubmitButton() {
	submitButton.click();
	return pages.internalPage;
  }
}
